﻿@model PersonalAccount_ResetPwd
@{
    ViewData["Title"] = "Index";
    Layout = "~/Views/Shared/_OridinaryPage.cshtml";
}

@section Header{
    <link rel="stylesheet" href="~/css/common.css" />
    <link rel="stylesheet" href="~/js/plugins/autoComplete/jquery.autocomplete.css" />
}

<section>
    <!--<h2>
        <small></small>
    </h2>-->
    <ol class="breadcrumb breadcrumb-pd clear-mgb bg-transparent">
        <li><a href="#"><i class="fa fa-dashboard"></i>个人域账号管理</a></li>
        <li class="active">密码丢失重置</li>
    </ol>
</section>
<!-- Main content -->
<section class="content-mini clear-pdt clear-pdb">
    <div class="row">
        <div class="col-xs-12">
            <div class="box clear-mgb">
                <!--<div class="box-header">
                    <h3 class="box-title"></h3>
                </div>-->
                <!-- /.box-header -->
                <div class="box-body">
                    <form class="form-horizontal" id="dataForm">
                        <input type="hidden" id="DeptId" name="DeptId" />
                        <input type="hidden" id="DeptName" name="DeptName" />
                        <input type="hidden" id="Id" name="Id" value="@Model.Id" />
                        <input type="hidden" id="TaskId" name="TaskId" value="@ViewBag.TaskId" />
                        <input type="hidden" id="Action" name="Action" value="" />
                        <div class="form-group">
                            <div class="container-fluid">
                                <div class="row">
                                    <div class="col-xs-12">
                                        <div class="row">
                                            <div class="col-xs-3">
                                                <label for="UserCode" class="col-xs-2 control-label text-left pd-lft pd-rt">域账号</label>
                                                <div class="col-xs-10">
                                                    <input type="text" class="form-control userAC" id="UserCode" name="UserCode" placeholder="域账号" maxlength="30" value="@Model.UserCode">
                                                </div>
                                            </div>
                                            <div class="col-xs-3">
                                                <label for="FirstDeptCode" class="col-xs-2 control-label text-left pd-lft pd-rt">一级部门</label>
                                                <div class="col-xs-10">
                                                    @Html.DDLDepartment1("FirstDeptCode", Model.FirstDeptCode, new { @id = "FirstDeptCode", @class = "form-control", @onchange = "setSecondDept()" }, null, 0)
                                                </div>
                                            </div>
                                            <div class="col-xs-3">
                                                <label for="SecondDeptCode" class="col-xs-2 control-label text-left pd-lft pd-rt">二级部门</label>
                                                <div class="col-xs-10">
                                                    <select id="SecondDeptCode" name="SecondDeptCode" class="form-control" onchange="setThirdDept()"></select>
                                                </div>
                                            </div>
                                            <div class="col-xs-3">
                                                <label for="ThirdDeptCode" class="col-xs-2 control-label text-left pd-lft pd-rt">三级部门</label>
                                                <div class="col-xs-10">
                                                    <select id="ThirdDeptCode" name="ThirdDeptCode" class="form-control" onchange="setManager()"></select>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="container-fluid">
                                <div class="row">
                                    <div class="col-xs-12">
                                        <div class="row">
                                            <div class="col-xs-3">
                                                <label for="DeptManager" class="col-xs-2 control-label text-left pd-lft pd-rt">部门经理</label>
                                                <div class="col-xs-10">
                                                    <input type="text" class="form-control" id="DeptManager" name="DeptManager" placeholder="部门经理" readonly="readonly" maxlength="30" value="@Model.DeptManager">
                                                </div>
                                            </div>
                                            <div class="col-xs-3">
                                                <label for="ProxyMan" class="col-xs-2 control-label text-left pd-lft pd-rt">代申请人</label>
                                                <div class="col-xs-10">
                                                    <input type="text" readonly="readonly" class="form-control" id="ProxyMan" name="ProxyMan" placeholder="代申请人" value="@(Model.ProxyMan ?? SessionUtility.GetBasicUserInfo().PinyinCode)">
                                                </div>
                                            </div>
                                            <div class="col-xs-3">
                                                <label for="CreateDate" class="col-xs-2 control-label text-left pd-lft pd-rt">申请时间</label>
                                                <div class="col-xs-10">
                                                    <input type="text" readonly="readonly" class="form-control" id="CreateDate" name="CreateDate" placeholder="申请时间" value="@(Model.CreateDate)">
                                                </div>
                                            </div>
                                            <div class="col-xs-3">
                                                <label for="Remarks" class="col-xs-2 control-label text-left pd-lft pd-rt">重置原因</label>
                                                <div class="col-xs-10">
                                                    <input type="text" class="form-control" id="Remarks" name="Remarks" maxlength="200" placeholder="重置原因，200字内" value="@Model.Remarks">
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>

                    </form>
                    <div class="form-group" style="text-align:center;margin-top:10px;">
                        @if (ViewBag.IsCheckman && ViewBag.Resubmit)
                        {
                            foreach (WorkflowTransition item in ViewBag.ActionList)
                            {
                                <button type="button" class="btn btn-blue boxShadowNone btnWidth120 submit" value="@item.Code">@item.Name</button>
                            }
                        }
                        else
                        {
                            <button type="button" class="btn btn-blue boxShadowNone btnWidth120 submit">提交</button>
                        }

                    </div>
                </div>
                <!-- /.box-body -->
            </div>
            <!-- /.box -->
            <div class="guidance">
                <div class="top-info">说明:</div>
                1.密码将会在审批通过后的15分钟后被重置<br />
                2.重置后的密码将发送到域帐号对应的NOTES邮箱；特殊帐号对应为帐号责任人的outlook邮箱<br />
                3.密码重置后，域帐号必须登录计算机，并重新修改密码，才能使用<br />
            </div>
        </div>
        <!-- /.col -->
    </div>
    <!-- /.row -->
</section>
<!-- /.content -->

@section Scripts{
    <script src="~/js/plugins/autoComplete/jquery.autocomplete.js"></script>
    <script src="~/js/layer-extend.js"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            //[AutoComplete]1、禁止输入逗号
            $(".userAC").keydown(function () {
                if (event.keyCode == 188) {
                    return false;
                }
            });

            //[AutoComplete]2、对域账号控件绑定自动完成功能
            if ($(".userAC").autocomplete) {
                var url = '@Url.Content("~/ACUser/GetUserCnsamList/")';
                $(".userAC").autocomplete(url, {
                    width: 300,
                    multiple: false,
                    mustMatch: true,
                    formatItem: getCnsamComplexstring,
                    formatResult: getSamFromComplexstring
                }).result(function (event, item) {
                    //showUserMessage();
                });
            }

            if ("123456A".startsWith("123456")) {
                alert("aaa.startsWith(123456) is true");
            } else {
                alert("aaa.startsWith(123456) is false");
            }

            if ("A123456".endsWith("123456")) {
                alert("aaa.endsWith(123456) is true");
            } else {
                alert("aaa.endsWith(123456) is false");
            }
        });

        if ('@ViewBag.Resubmit'.toLowerCase() == 'false' && '@(SessionUtility.GetBasicUserInfo().ThirdDeptCode)' != "") {
            $("#FirstDeptCode").val('@(SessionUtility.GetBasicUserInfo().FirstDeptCode)');
            setSecondDept();
            $("#SecondDeptCode").val('@(SessionUtility.GetBasicUserInfo().SecondDeptCode)');
            setThirdDept();
            $("#ThirdDeptCode").val('@(SessionUtility.GetBasicUserInfo().ThirdDeptCode)');
            setManager();
        } else {
            $("#FirstDeptCode").val('@(Model.FirstDeptCode)');
            setSecondDept();
            $("#SecondDeptCode").val('@(Model.SecondDeptCode)');
            setThirdDept();
            $("#ThirdDeptCode").val('@(Model.ThirdDeptCode)');
            setManager();
        }

        function setSecondDept() {
            $("#SecondDeptCode").empty();
            var dept1Code = $("#FirstDeptCode").val();
            $.ajax({
                url: "/Sys/Sys_Department/GetDept2",
                data: "dept1Code=" + dept1Code + "&hasExtra=false&isHistory=0",
                method: "get",
                async: false,
                dataType: "json",
                success: function (data) {
                    $.each(data, function (i, item) {
                        $("<option></option>")
                            .val(item["Dept2Code"])
                            .text(item["Dept2Name"])
                            .appendTo($("#SecondDeptCode"));
                    });
                    setThirdDept();
                },
                error: function (err) { }
            });
        }

        function setThirdDept() {
            $("#ThirdDeptCode").empty();
            var dept2Code = $("#SecondDeptCode").val();
            $.ajax({
                url: "/Sys/Sys_Department/GetDept3",
                data: "dept2Code=" + dept2Code + "&hasExtra=false&isHistory=0",
                method: "get",
                async: false,
                dataType: "json",
                success: function (data) {
                    $.each(data, function (i, item) {
                        $("<option></option>")
                            .val(item["Dept3Code"])
                            .text(item["Dept3Name"])
                            .appendTo($("#ThirdDeptCode"));
                    });
                    setManager();
                },
                error: function (err) { }
            });
        }

        function setManager() {
            var dept1Code = $("#FirstDeptCode").val();
            var dept2Code = $("#SecondDeptCode").val();
            var dept3Code = $("#ThirdDeptCode").val();
            if (dept1Code == "-1" || dept2Code == "-1" || dept3Code == "-1") {
                return;
            }
            $.ajax({
                url: "/Sys/Sys_Department/GetManagerAndId",
                data: "dept1Code=" + dept1Code + "&dept2Code=" + dept2Code + "&dept3Code=" + dept3Code,
                method: "get",
                async: false,
                dataType: "json",
                success: function (data) {
                    $("#DeptManager").val(data.DeptManager);
                    $("#DeptId").val(data.DeptId);
                },
                error: function (err) { }
            });
        }

        $(".submit").click(function () {
            var userCode = $("#UserCode").val();
            var firstDeptCode = $("#FirstDeptCode").val();
            var secondDeptCode = $("#SecondDeptCode").val();
            var thirdDeptCode = $("#ThirdDeptCode").val();
            var deptName = $("#ThirdDeptCode").find("option:selected").text();
            var deptManager = $("#DeptManager").val();
            var remarks = $("#Remarks").val();
            var taskId = $("#TaskId").val();
            if (IsNullOrEmpty(userCode)) {
                alert("请输入域账号！");
                return;
            }
            if (IsNullOrEmpty(firstDeptCode)) {
                alert("请选择一级部门！");
                return;
            }
            if (IsNullOrEmpty(secondDeptCode)) {
                alert("请选择二级部门！");
                return;
            }
            if (IsNullOrEmpty(thirdDeptCode)) {
                alert("请选择三级部门！");
                return;
            }
            if (IsNullOrEmpty(deptManager)) {
                alert("部门经理不能为空！");
                return;
            }
            if (deptManager.split(" ").length != 2) {
                alert("部门经理数据格式错误！");
                return;
            }
            if (IsNullOrEmpty(remarks)) {
                alert("请输入重置原因！");
                return;
            }
            IndexBtnDisabled();
            $("#Action").val($(this).val());
            $("#DeptName").val(deptName);
            $.ajax({
                type: "post",
                url: "/PersonalAccount/PersonalAccount_ResetPwd/Submit",
                data: $("#dataForm").serialize(),
                dataType: "json",
                success: function (data) {
                    if (data.Success) {
                        $("#UserCode").val('');
                        $("#CreateDate").val(GetCurrentTime());
                        $("#Remarks").val('');
                        if (IsNullOrEmpty(taskId)) {
                            //插入成功后跳转到首页
                            activeTopTabByPageId("10008");
                            activeAndRefreshSubmitedListTab();
                        } else {
                            closeAndRefreshUnderCheckingList();
                        }
                        alert(data.Message);
                    } else {
                        alert(data.Message);
                    }
                    IndexBtnEnabled();
                },
                error: function (err) { }
            });
        });
    </script>
}